<template>
  <div v-if="isImportWork">
    <Modal footer-hide v-model="isImportWork" title="导入作业">
      <Form :label-width="80">
        <FormItem label="导入成员">
          {{ importMember.nickname }}({{ importMember.qq }})
        </FormItem>
        <FormItem label="时间">
          <DatePicker
            class="w150"
            type="date"
            format="yyyy-MM-dd"
            v-model="importDate"
          ></DatePicker>
          <TimePicker
            class="w150"
            type="time"
            v-model="importTime"
          ></TimePicker>
        </FormItem>
        <FormItem label="内容">
          <Input type="textarea" :rows="4" v-model="importText"></Input>
        </FormItem>
        <FormItem>
          <Button @click="doImportWork">导入</Button>
        </FormItem>
      </Form>
    </Modal>
  </div>
</template>
<script>
import { getDateByStr, getTimeByStr } from "js/utils.js";
export default {
  props: ["importMember"],
  data() {
    return {
      isImportWork: true,
      importDate: "",
      importTime: "",
      importText: "",
    };
  },
  watch: {
    isImportWork(newval) {
      if (!newval) {
        this.$emit("close");
      }
    },
  },
  methods: {
    initData() {
      this.importDate = getDateByStr();
      this.importTime = getTimeByStr();
      this.importText = "";
    },
    doImportWork() {
      if (!this.importDate) {
        this.$global.log("请选择日期");
        return;
      }
      if (!this.importTime) {
        this.$global.log("请选择时间");
        return;
      }
      if (!this.importText) {
        this.$global.log("请选择导入内容");
        return;
      }
      let importDate = this.importDate;
      let importTime = this.importTime;
      if (importDate instanceof Date) {
        importDate = getDateByStr(importDate);
      }
      if (importTime instanceof Date) {
        importTime = getTimeByStr(importTime);
      }
      let time = importDate + " " + importTime;
      this.$emit("save", {
        time: time,
        content: this.importText,
      });
    },
  },
  mounted() {
    this.initData();
  },
};
</script>
